package com.example.administrator.myapplication;

import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.example.administrator.myapplication.fragments.LcFragment;
import com.example.administrator.myapplication.fragments.MyFragment;
import com.example.administrator.myapplication.fragments.ShFragment;
import com.example.administrator.myapplication.fragments.SyFragment;

public class MainActivity extends AppCompatActivity {

    ImageView mIvMy;
    MyFragment myFragment;
    ImageView mIvSh;
    ShFragment shFragment;
    ImageView mIvHome;
    SyFragment syFragment;
    ImageView mIvLc;
    LcFragment lcFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initFragment();
        initView();
        initEvent();
    }

    private void initFragment() {
        myFragment = new MyFragment();
        shFragment = new ShFragment();
        syFragment = new SyFragment();
        lcFragment = new LcFragment();
    }


    private void initEvent() {
        mIvMy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.container,myFragment)
                        .commit();
            }
        });
        mIvSh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.container,shFragment)
                        .commit();
            }
        });
        mIvHome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.container,syFragment)
                        .commit();
            }
        });
        mIvLc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.container,lcFragment)
                        .commit();
            }
        });
    }


    @SuppressLint("WrongViewCast")
    private void initView() {
        mIvMy = findViewById(R.id.iv_my);
        mIvSh = findViewById(R.id.iv_sh);
        mIvHome = findViewById(R.id.iv_home);
        mIvLc = findViewById(R.id.iv_lc);

    }



}
